home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / lprm / lprm.c < prev    next >
C/C++ Source or Header  |  1992-04-18  |  3KB  |  121 lines

  1. /*
  2.  * Copyright (c) 1983 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that this notice is preserved and that due credit is given
  7.  * to the University of California at Berkeley. The name of the University
  8.  * may not be used to endorse or promote products derived from this
  9.  * software without specific prior written permission. This software
  10.  * is provided ``as is'' without express or implied warranty.
  11.  */
  12.  
  13. #ifndef lint
  14. char copyright[] =
  15. "@(#) Copyright (c) 1983 Regents of the University of California.\n\
  16.  All rights reserved.\n";
  17. #endif /* not lint */
  18.  
  19. #ifndef lint
  20. static char sccsid[] = "@(#)lprm.c    5.3 (Berkeley) 5/5/88";
  21. #endif /* not lint */
  22.  
  23. /*
  24.  * lprm - remove the current user's spool entry
  25.  *
  26.  * lprm [-] [[job #] [user] ...]
  27.  *
  28.  * Using information in the lock file, lprm will kill the
  29.  * currently active daemon (if necessary), remove the associated files,
  30.  * and startup a new daemon.  Priviledged users may remove anyone's spool
  31.  * entries, otherwise one can only remove their own.
  32.  */
  33.  
  34. #include "lp.h"
  35.  
  36. /*
  37.  * Stuff for handling job specifications
  38.  */
  39. char    *user[MAXUSERS];    /* users to process */
  40. int    users;            /* # of users in user array */
  41. int    requ[MAXREQUESTS];    /* job number of spool entries */
  42. int    requests;        /* # of spool requests */
  43. char    *person;        /* name of person doing lprm */
  44.  
  45. static char    luser[16];    /* buffer for person */
  46.  
  47. struct passwd *getpwuid();
  48.  
  49. static usage();
  50.  
  51. #ifdef sprite
  52. int debug;
  53. #endif
  54.  
  55. main(argc, argv)
  56.     char *argv[];
  57. {
  58.     register char *arg;
  59.     struct passwd *p;
  60.     struct direct **files;
  61.     int nitems, assasinated = 0;
  62.  
  63.     name = argv[0];
  64. #ifdef sprite
  65.         strcpy(host,"sprite.Berkeley.EDU");
  66. #else
  67.     gethostname(host, sizeof(host));
  68. #endif
  69.     openlog("lpd", 0, LOG_LPR);
  70.     if ((p = getpwuid(getuid())) == NULL)
  71.         fatal("Who are you?");
  72.     if (strlen(p->pw_name) >= sizeof(luser))
  73.         fatal("Your name is too long");
  74.     strcpy(luser, p->pw_name);
  75.     person = luser;
  76.     while (--argc) {
  77.         if ((arg = *++argv)[0] == '-')
  78.             switch (arg[1]) {
  79.             case 'P':
  80.                 if (arg[2])
  81.                     printer = &arg[2];
  82.                 else if (argc > 1) {
  83.                     argc--;
  84.                     printer = *++argv;
  85.                 }
  86.                 break;
  87.             case '\0':
  88.                 if (!users) {
  89.                     users = -1;
  90.                     break;
  91.                 }
  92.             default:
  93.                 usage();
  94.             }
  95.         else {
  96.             if (users < 0)
  97.                 usage();
  98.             if (isdigit(arg[0])) {
  99.                 if (requests >= MAXREQUESTS)
  100.                     fatal("Too many requests");
  101.                 requ[requests++] = atoi(arg);
  102.             } else {
  103.                 if (users >= MAXUSERS)
  104.                     fatal("Too many users");
  105.                 user[users++] = arg;
  106.             }
  107.         }
  108.     }
  109.     if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
  110.         printer = DEFLP;
  111.  
  112.     rmjob();
  113. }
  114.  
  115. static
  116. usage()
  117. {
  118.     printf("usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n");
  119.     exit(2);
  120. }
  121.